<?php

class User_SearchController extends Zend_Controller_Action
{
  function init() {
    $this->getHelper('viewRenderer')->setNoRender();
  }

  function bypseudoAction() {
  	
	$q = $this->_getParam('q');
	$where = $this->_getParam('where');
	$perPage = $this->_getParam('perPage');
	$page = $this->_getParam('page');
	require_once('Myzen/User.php');
	
	try{
		$oUsers = Myzen_User::search('pseudo',$q,$where,$perPage,$page);
	} catch(Myzen_User_Exception $e) {
      $data['status'] = 'KO';
      $data['error']['num'] = 	$e->getCode();
      $data['error']['message'] = 	$e->getMessage();
      echo Zend_Registry::get('dt_serializer')->serialize($data);	
      return;		
	}
	
	$data['status'] = 'OK';	
	if(empty($oUsers)) $data['users'] = array();
	else {
		foreach($oUsers as $num => $oUser) $data['users'][] = $oUser->asArray();	
	}
	echo Zend_Registry::get('dt_serializer')->serialize($data);
	
  }
 
 
 
 
 
 
   function byemailAction() {
  	
	$q = $this->_getParam('q');
	$where = $this->_getParam('where');
	$perPage = $this->_getParam('perPage');
	$page = $this->_getParam('page');
	require_once('Myzen/User.php');
	
	try{
		$oUsers = Myzen_User::search('email',$q,$where,$perPage,$page);
	} catch(Myzen_User_Exception $e) {
      $data['status'] = 'KO';
      $data['error']['num'] = 	$e->getCode();
      $data['error']['message'] = 	$e->getMessage();
      echo Zend_Registry::get('dt_serializer')->serialize($data);	
      return;		
	}
	
	$data['status'] = 'OK';	
	if(empty($oUsers)) $data['users'] = array();
	else {
		foreach($oUsers as $num => $oUser) $data['users'][] = $oUser->asArray();	
	}
	echo Zend_Registry::get('dt_serializer')->serialize($data);
	
  }
 
 
 
 


} //End class


?>